﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>SmartText help file</title>
    <style type="text/css">
        span
        {
            color: #BDAE9D;
        }
        .sc0
        {
            color: #FFFFFF;
        }
        .sc4
        {
            color: #FF3A83;
        }
        .sc6
        {
            color: #80FF80;
        }
        .sc16
        {
            font-weight: bold;
            color: #00FF80;
        }
        .sc17
        {
            color: #FF8040;
        }
        .sc24
        {
        }
        .sc99
        {
            font-family: Courier New;
            background: #000000;
            color: #66CCFF;
        }
        .detail
        {
            font-size: small;
            font-family: Courier New;
            background: #AfAfAf;
        }
        .error
        {
            font-family: Courier New;
            background: #AfAfAf;
            color: #FF0000;
        }
    </style>
</head>
<body>
    <div id="main">
        <div id="navigation">
            <h1>
                Smart Text</h1>
            <ul>
                <li><a href="#intro">Introduction</a></li>
                <li><a href="#getting started">Getting Started</a></li>
                <li><a href="#template">Template</a>
                    <ul>
                        <li><a href="#variable">Variable</a></li>
                        <li><a href="#control">Flow Controlling</a>
                            <ul>
                                <li><a href="#if">if</a></li>
                                <li><a href="#for">for</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li><a href="#parameter">Parameter</a>
                    <ul>
                        <li><a href="#csv">CSV Parameter File</a></li>
                        <li><a href="#xml">XML Parameter File</a></li>
                        <li><a href="#lua">LUA Parameter File</a></li>
                    </ul>
                </li>
                <li><a href="#error handling">Error Handling</a>
                    <ul>
                        <li><a href="#lua error">Lua Error</a></li>
                        <li><a href="#undefine variable">Undefined Variable Error</a></li>
                    </ul>
                </li>
                <li><a href="#command line">Command Line</a></li>
                <!--<li><a href="#useltt">Using LuaTextTemplate in your own code</a></li>-->
                <!--<li><a href="#about">About</a></li>-->
            </ul>
        </div>
    </div>
    <br />
    <hr />
    <div id="content">
        <h2>
            <a name="intro">Introduction</a></h2>
        <p>
                    SmartText is a tool of generating text.<br />
        It can help you rapidly generating lots of text (Like code, report, configuration files, etc.).This help file is also generated by SmartText.<br />
        SmartText has a built-in text template engine (similar to Velocity), also provides a fancy and friendly GUI for better user experience.
    
        </p>
        <br />
        <br />
                Features :<ul>
        <li>Use very simple Lua syntax to create template (extremely flexible!)</li>
        <li>Support 3 types of parameter files</li>
        <ul>
            <li>.csv</li>
            <li>.xml</li>
            <li>.lua</li>
        </ul>
        <li>Support command line arguments</li>
        <li>Support multi-languages(English, Chinese and Japanese)</li>
        <li>Friendly GUI</li>
        </ul>
    
        <br />
        <br />
        <hr />
        <h2>
            <a name="getting started">Getting Started</a></h2>
        <p>
                    SmartText needs to be run on Windows XP/Vista/7 and above OS.<br />
        Also needs .Net Framework 4.0 and above installed.<br />
        Double click SmartText.exe to run.<br />
    
        </p>
        <img src="Images/mainui_english.jpg" /><br />
        <p>
                    Nice GUI huh? OK, let’s see what SmartText can do for you.
    </p>
        <ul>
            <li>        Making Template File<br />
        Type following text by using any your favorite text editor, and save to "template.txt"(any location) <br />
    
                <br />
                <div class="sc99">
                    <span class="sc0">Hello</span><span class="sc24"> </span><span class="sc16">${person.name}</span><span
                        class="sc0">!</span><span class="sc24">
                            <br />
                        </span><span class="sc0">This</span><span class="sc24"> </span><span class="sc0">year</span><span
                            class="sc24"> </span><span class="sc16">${person.name}</span><span class="sc24">
                    </span><span class="sc0">is</span><span class="sc24"> </span><span class="sc16">${person.age}</span><span
                        class="sc24"> </span><span class="sc0">years</span><span class="sc24"> </span>
                    <span class="sc0">old.</span><span class="sc24"><br />
                    </span><span class="sc0">Next</span><span class="sc24"> </span><span class="sc0">year</span><span
                        class="sc24"> </span><span class="sc16">${person.name}</span><span class="sc24">
                    </span><span class="sc0">is</span><span class="sc24"> </span><span class="sc16">${person.age+1}</span><span
                        class="sc24"> </span><span class="sc0">years</span><span class="sc24"> </span>
                    <span class="sc0">old.</span></div>
                <br />
            </li>
            <li>        Making Parameter File<br />
        Again, type following text, save to "parameter.xml"(any location).<br />
    
                <br />
                <div class="sc99">
                    &lt;person&gt;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;<span class="sc0">WAKU</span>&lt;/name&gt;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&lt;age&gt;<span class="sc0">29</span>&lt;/age&gt;<br />
                    &lt;/person&gt;<br />
                </div>
                <br />
            </li>
            <li>        Using SmartText<br />
        In "Template File", select saved "template.txt" file, <br />
        In "Parameter File", select saved "parameter.xml" file, <br />
        Leave "Output File" empty, <br />
        Click "Generate" button, if everything's ok, you will see the following output text :<br />
    
                <img src="Images/sample_result_english.jpg" /><br />
            </li>
        </ul>
        <p>
                    So, smart as you can figure out SmartText's capability?
    </p>
        <br />
        <br />
        <hr />
        <h2>
            <a name="template">Template</a></h2>
        <p>
                    SmartText's template is a skeleton of the text to be generated.<br />
        There are some marks in template, to distinguish normal text and special text.<br />
        SmartText mainly uses Lua syntax as template syntax,<br />
        So if you’re familiar with Lua, you will easily grasp SmartText's template.<br />
        if not, it's ok, you just need to learn a couple of simple structures.<br />
    
        </p>
        <h3>
            <a name="variable">Variable</a></h3>
        <p>
                    By passing through the example in <a href="#getting started">Getting Started</a>, you should probably know the syntax of variable in SmartText's template:<br />
    
        </p>
        <div class="sc99">
            <span class="sc16">${<i>expression</i>}</span>
        </div>
        <br />
        <p>
                    Any valid expression of Lua, SmartText will evaluate it, and replace its representation with evaluating result.<br />
        Due to Lua, we can easily set a default value to a variable, like :<br />
    
        </p>
        <div class="sc99">
            <span class="sc16">${person.name or 'somebody'}</span>
        </div>
        <br />
        <p>
                    If person.name is nil (means nothing in Lua), use the value after "or"(here is a string "somebody").<br />
        Note that string can be surrounded by either double quote (") or single quote (') in Lua.<br />
        <br />
        All the examples before demonstrate a very important thing, using dot (.) to express hierarchical data structure.<br />
        We look into that in more detail later in <a href="#parameter">Parameter</a><br />
    
        </p>
        <h3>
            <a name="control">Flow Controlling</a></h3>
        <p>
                    In template, condition statement (if) and repeat statement (for) can be used to control the flow of text generating.<br />
        Because SmartText uses Lua inside (The template will be parsed into Lua code), so all the flow controlling statements use standard Lua syntax.<br />
        Only need to use #{} form.<br />
    
        </p>
        <div class="sc99">
            <span class="sc17">#{<i>Lua statement</i>}</span>
        </div>
        <br />
        <h4>
            <a name="#if">if</a></h4>
        <p>
                    See the following example:
    <br />
        </p>
        <div class="sc99">
            <span class="sc17">#{if person.age &lt; 18 then}<br />
            </span><span class="sc16">${person.name}</span><span class="sc24"> </span><span
                class="sc0">is</span><span class="sc24"> </span><span class="sc0">a</span><span class="sc24">
                </span><span class="sc0">child.<br />
                </span><span class="sc17">#{else}<br />
                </span><span class="sc16">${person.name}</span><span class="sc24"> </span><span
                    class="sc0">is</span><span class="sc24"> </span><span class="sc0">an</span><span
                        class="sc24"> </span><span class="sc0">adult.<br />
                        </span><span class="sc17">#{end}</span></div>
        <br />
        <p>
            		In this example, if statement is used to make decision between "child" and "adult".<br />
		By using the previous xml parameter, the output text will be:<br />
    
        </p>
        <div class="sc99">
            WAKU is an adult.
        </div>
        <br />
        <p>
                    Here is the complete syntax of if in Lua:
    
        </p>
        <div class="sc99">
            stat ::= if exp then block {elseif exp then block} [else block] end
        </div>
        <p>
            		Lua operator can also be used in condition statement. Following is a brief table of operators.
    
			</p>
            <table border="1" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111">
                <tr align="center">
                    <td>
                                Operator
    
                    </td>
                    <td>
                                Meaning
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        ==
                    </td>
                    <td>
                                Equal
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        ~=
                    </td>
                    <td>
                                Not Equal
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        &lt
                    </td>
                    <td>
                                Less than
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        &gt
                    </td>
                    <td>
                                Great than
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        &lt=
                    </td>
                    <td>
                        		Less than or Equal to
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        &gt=
                    </td>
                    <td>
                                Great than or Equal to
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        and
                    </td>
                    <td>
                                And
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        or
                    </td>
                    <td>
                                Or
    
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        not
                    </td>
                    <td>
                                Not
    
                    </td>
                </tr>
            </table>
            <h4>
                <a name="#for">for</a></h4>
            <p>
                		For statement is very useful, it can repeatedly generate a part of text.<br />
		For statement has two forms: one numeric and one generic. Let’s see the first.
    </p>
            <div class="sc99">
                <span class="sc17">#{for i = 1, 5 do}<br />
                </span><span class="sc0">i = </span><span class="sc16">${i}</span><br />
                <span class="sc17">#{end}</span></div>
            <br />
            <p>
                		This template is so simple even need no parameter to generate result:<br />
    
            </p>
            <div class="sc99">
                i = 1<br />
                i = 2<br />
                i = 3<br />
                i = 4<br />
                i = 5
            </div>
            <br />
            <p>
                		Following is the syntax of numeric form:
    </p>
            <div class="sc99">
                stat ::= for Name `=´ exp1 `,´ exp2 [`,´ exp3] do block end
            </div>
            		exp1 is the initial value,<br />
		exp2 is the termination value,<br />
		exp3 is the step value, when omitted, 1 as default.
    
            <p>
                		However, in practice, we often use another form: generic for <br />
        Before demonstration, we need to expand our parameter file:
    
            </p>
            <div class="sc99">
                &lt;list&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;person&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;<span class="sc0">WAKU</span>&lt;/name&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;age&gt;<span class="sc0">29</span>&lt;/age&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;/person&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;person&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;<span class="sc0">Joey</span>&lt;/name&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;age&gt;<span class="sc0">2</span>&lt;/age&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;/person&gt;<br />
                &lt;/list&gt;</div>
            <br />
            <p>
                		Then use generic for like this:
    
            </p>
            <div class="sc99">
                <span class="sc17">#{for p in enum(list.person) do}</span><br />
                <span class="sc24"></span><span class="sc0">NAME:</span><span class="sc24"> </span>
                <span class="sc16">${p.name}</span><span class="sc24"> </span><span class="sc0">AGE:</span><span
                    class="sc24"> </span><span class="sc16">${p.age}</span><span class="sc24"><br />
                    </span><span class="sc17">#{end}</span></div>
            <br />
            <p>
                		The result:
    </p>
            <div class="sc99">
                NAME: WAKU AGE: 29<br />
                NAME: Joey AGE: 2
            </div>
            <br />
            <p>
                		SmartText parses XML parameter into Lua code (detail in <a href="#parameter">Parameter</a>), <br />
        "person" is a Lua Table(used as an array here), can be accessed by "list.person".<br />
        SmartText provides a very handy function "enum" to enumerate element of a Table,<br />
        So "enum(list.peronson)" is enumerating every person, which is assigned to "p".<br />
    <p>
                <br />
                <div class="detail">
                    <ul>
                                <li>Technical Details:</li><br />
		"enum" is a function provided by SmartText, not by Lua, <br />
		"enum" can enumerate not only array-form Table in Lua, but also .Net array, collection(List, Dictionary, etc.), and all objects that implement the IEnumerable interface, <br />
		When enumerating Lua Table, it's similar to Lua function "ipairs", the difference is, ipairs returns two values(index and value), but enum only returns value.<br />
		About specific implementation of enum function, you can view the source code of SmartText.
    
                    </ul>
                </div>
            </p>
            <p>
                		The syntax of generic for:
    </p>
            <div class="sc99">
                stat ::= for namelist in explist do block end
            </div>
            <p>
                		Above is all the explanations about flow controlling, mainly if and for, but SmartText and Lua have a very flexible combination, <br />
		In fact, you can insert any valid Lua statements into #{...}, they will be parsed into Lua code and executed.<br />
		You can define global variables in #{...}, and use it somewhere else.<br />
		You can even define functions, in order to implement macros like Velocity does.
	    </p>
            <br />
            <br />
            <hr />
            <h2>
                <a name="parameter">Parameter</a></h2>
            <p>
                		SmartText supports three types of parameter files (CSV XML LUA), even though they have similar usage (provide data to template),<br />
		but each type has its own advantages and disadvantages, you should use appropriate type on different occasions.<br />
		SmartText parses CSV and XML parameter files to Lua code. You needn't to grasp the details of parsing, only need to know how to use data correctly.
    
            </p>
            <a name="csv">CSV Parameter File</a>
            <p>
                		CSV parameter file is the easiest type, it has a straightforward data relationship. You can use EXCEL to edit CSV files.<br />
		The row-column form is also correspond to database table, so if you want to use a database table as a parameter, then, the CSV parameter file is most appropriate.<br />
		However, CSV parameter file cannot represent hierarchical relationships of data structure, then you need to consider the use of XML or LUA parameter files.
	
            </p>
            <h3>
                        Example:
    </h3>
            <p>
                		Template file:
    </p>
            <div class="sc99">
                <span class="sc16">${parameter[1].name}</span><span class="sc24"> </span><span class="sc0">
                    is</span><span class="sc24"> </span><span class="sc16">${parameter[1].age}</span><span
                        class="sc24"> </span><span class="sc0">years</span><span class="sc24"> </span>
                <span class="sc0">old.</span><br />
                <span class="sc24"></span><span class="sc16">${parameter[2].name}</span><span class="sc24">
                </span><span class="sc0">is</span><span class="sc24"> </span><span class="sc16">${parameter[2].age}</span><span
                    class="sc24"> </span><span class="sc0">years</span><span class="sc24"> </span>
                <span class="sc0">old.</span><span class="sc24"> </span>
            </div>
            <p>
                        Parameter file
    "parameter.csv":</p>
            <div class="sc99">
                name,age<br />
                WAKU,29<br />
                Joey,2</div>
            <p>
                        Generated result:
    </p>
            <div class="sc99">
                WAKU is 29 years old.<br />
                Joey is 2 years old.</div>
            <p>
                		Since CSV file has no root element like XML file, so SmartText uses CSV file name as a prefix of each variable.<br />
		In above example, the CSV parameter file's name is "parameter", so the prefix of each variable is "parameter".<br />
		Use subscript form "parameter[1]" to access the the line "WAKU,29" (the subscripts of Lua array starts from 1), <br />
		Access the content of column "name" is also straightforward: "parameter[1].name".<br />
	    
            </p>
            <div class="detail">
                <ul>
                    		<li>Technical Details:</li><br />
		Actually, the parameter has become to a Lua Table.<br />
		SmartText parses CSV parameter files into nested Table, <br />
		Each line in CSV file (exclude the first line, it is the header line) will be parsed into a child Table.<br />
		The parsing result of the CSV file in previous example is as follows:
    
                    <br />
                    parameter&nbsp;=&nbsp;<br />
                    {<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['name']&nbsp;=&nbsp;'WAKU',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['age']&nbsp;=&nbsp;29,<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['name']&nbsp;=&nbsp;'Joey',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['age']&nbsp;=&nbsp;2,<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    }<br />
                </ul>
            </div>
            <p>
                		The above example works well, though; the template was slightly awkward, <br />
		Using generic for, you can use the following template form to get exactly the same result:
    
            </p>
            <div class="sc99">
                <span class="sc17">#{for p in enum(parameter) do}</span><span class="sc24"> </span>
                <br />
                <span class="sc16">${p.name}</span><span class="sc24"> </span><span class="sc0">is</span><span
                    class="sc24"> </span><span class="sc16">${p.age}</span><span class="sc24">
                </span><span class="sc0">years</span><span class="sc24"> </span><span class="sc0">old.</span><br />
                <span class="sc24"></span><span class="sc17">#{end}</span></div>
            <p>
                		It is worth mentioning that, SmartText uses LumenWorks parsing CSV files, LumenWorks is the best .Net CSV parser in my opinion.
    
            </p>
            <br />
            <a name="xml">XML Parameter File</a>
            <p>
                		XML is a very popular file format, and has good compatibility. The tree-form is very suitable to represent the data structure with a hierarchical relationship.<br />
		.Net also have an excellent support for XML, you can serialize an object to XML file, a Dataset object can be directly written to XML file and so on.<br />
		The disadvantage of XML file maybe somewhat lengthy, editing is a little inconvenient without a handy tool.<br />
		Same with CSV, SmartText parses XML parameter file into Lua code.
    
            </p>
            <h3>
                        Example:
    </h3>
            <p>
                		Template file:
    </p>
            <div class="sc99">
                <span class="sc17">#{for p in enum(list.person) do}</span><br />
                <span class="sc24"></span><span class="sc16">${p.name}</span><span class="sc24">
                </span><span class="sc0">is</span><span class="sc24"> </span><span class="sc16">${p.age}</span><span
                    class="sc24"> </span><span class="sc0">years</span><span class="sc24"> </span>
                <span class="sc0">old.</span><br />
                <span class="sc24"></span><span class="sc16">${p.name}</span><span class="sc24">
                </span><span class="sc0">likes</span><span class="sc24"> </span><span class="sc16">${join(p.favourite_food.food)}</span><span
                    class="sc0">.</span>
                <br />
                <span class="sc17">#{end}</span>
            </div>
            <p>
                        Parameter file
    "parameter.xml":</p>
            <div class="sc99">
                &lt;list&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;person<span class="sc3">&nbsp;name</span><span class="sc8">=</span><span
                    class="sc6">"WAKU"</span><span class="sc8">&nbsp;</span><span class="sc3">age</span><span
                        class="sc8">=</span><span class="sc6">"29"</span>&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;favourite_food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;food&gt;<span
                    class="sc0">rice</span>&lt;/food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;food&gt;<span
                    class="sc0">chicken</span>&lt;/food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/favourite_food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;/person&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;person<span class="sc3">&nbsp;name</span><span class="sc8">=</span><span
                    class="sc6">"Joey"</span><span class="sc8">&nbsp;</span><span class="sc3">age</span><span
                        class="sc8">=</span><span class="sc6">"2"</span>&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;favourite_food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;food&gt;<span
                    class="sc0">milk</span>&lt;/food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;food&gt;<span
                    class="sc0">juice</span>&lt;/food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;food&gt;<span
                    class="sc0">candy</span>&lt;/food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/favourite_food&gt;<br />
                &nbsp;&nbsp;&nbsp;&nbsp;&lt;/person&gt;<br />
                &lt;/list&gt;<br />
            </div>
            <p>
                        Generated result:
    </p>
            <div class="sc99">
                WAKU is 29 years old.<br />
                WAKU likes rice,chicken.<br />
                Joey is 2 years old.<br />
                Joey likes milk,juice,candy.<br />
            </div>
            <p>
                		This example demonstrates how to access the content of XML parameter correctly.<br />
		Just remember a few simple rules: <br />
		1. Variables start from the root node ("list" in the example) <br />
		2. Use DOT (.) to access attribute (like "name" and "age" in the example) <br />
		3. Also use DOT (.) to access child node <br />
		4. If a node appears more than once, it is an array, you can use the "enum" function for enumeration (like "person" and "food" in the example) <br />
		<br />
		There is a new function "join", it's also provided by SmartText.<br />
		It is used to concatenate string elements of an array, the first argument is same with "enum"(.Net array, collection or Lua Table); the second argument separator is optional, default is a comma(,).<br />
    
            </p>
            <div class="detail">
                <ul>
                    		<li> Technical Details: </ li> <br />
		The parsing result of the XML file in previous example is as follows:
	
                    <br />
                    list&nbsp;=&nbsp;<br />
                    {<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;['person']&nbsp;=&nbsp;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['name']&nbsp;=&nbsp;'WAKU',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['age']&nbsp;=&nbsp;29,<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['favourite_food']&nbsp;=&nbsp;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['food']&nbsp;=&nbsp;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'rice',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'chicken',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['name']&nbsp;=&nbsp;'Joey',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['age']&nbsp;=&nbsp;2,<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['favourite_food']&nbsp;=&nbsp;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;['food']&nbsp;=&nbsp;<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'milk',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'juice',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'candy',<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    &nbsp;&nbsp;&nbsp;&nbsp;},<br />
                    }<br />
                </ul>
            </div>
            <a name="lua">LUA Parameter File</a>
            <p>
                		Lua parameter file is the most efficient of the three types (as both CSV and XML are required to parse into Lua code first), and also the most flexible one.<br />
		Its disadvantage is not very popular, and using it needs a certain knowledge of Lua.<br />
		Lua parameter file can get exactly same result of previous examples, just use the Lua code in the technical details as a Lua parameter file.<br />
		But there are something that CSV and XML cannot do.
    </p>
                <h3>
                            Example:
    </h3>
                <p>
                    		Template file:
    </p>
                <div class="sc99">
                    <span class="sc0">a</span><span class="sc24"> </span><span class="sc0">=</span><span
                        class="sc24"> </span><span class="sc16">${a}</span><br />
                    <span class="sc24"></span><span class="sc0">b</span><span class="sc24"> </span><span
                        class="sc0">=</span><span class="sc24"> </span><span class="sc16">${b}</span><br />
                    <span class="sc24"></span><span class="sc0">c</span><span class="sc24"> </span><span
                        class="sc0">=</span><span class="sc24"> </span><span class="sc16">${c}</span><br />
                    <span class="sc24"></span><span class="sc0">a</span><span class="sc24"> </span><span
                        class="sc0">+</span><span class="sc24"> </span><span class="sc0">b</span><span class="sc24">
                        </span><span class="sc0">+</span><span class="sc24"> </span><span class="sc0">c</span><span
                            class="sc24"> </span><span class="sc0">=</span><span class="sc24"> </span>
                    <span class="sc16">${a + b + c}</span>
                </div>
                <p>
                            Parameter file
    "parameter.lua":</p>
                <div class="sc99">
                    <span class="sc11">a</span><span class="sc0"> </span><span class="sc10">=</span><span
                        class="sc0"> </span><span class="sc4">1</span><br />
                    <span class="sc0"></span><span class="sc11">b</span><span class="sc0"> </span><span
                        class="sc10">=</span><span class="sc0"> </span><span class="sc4">2</span><br />
                    <span class="sc0"></span><span class="sc11">c</span><span class="sc0"> </span><span
                        class="sc10">=</span><span class="sc0"> </span><span class="sc4">3</span></div>
    </div>
    <p>
                Generated result:
    </p>
    <div class="sc99">
        a = 1<br />
        b = 2<br />
        c = 3<br />
        a + b + c = 6
    </div>
    <p>
        		If you use CSV or XML, you have to quote the CSV template file name or the name of the XML root node, <br />
		The parameter also needs to be split by comma or placed into XML-TAG, while Lua parameter is very straightforward.<br />
		Note, however, that all these variables are defined as global, so you need to pay attention to naming conflicts.<br />
		Of course, if there are pretty much variables, you should get them organized by using Lua Table.
    
    </p>
    <br />
    <hr />
    <h2>
        <a name="error handling">Error Handling</a></h2>
    <p>
        		If an error was raised when generating text, SmartText will display the error message in the textbox with red color.
    
    </p>
    <h3>
        <a name="lua error">Lua Error</a></h3>
    <p>
        		As mentioned before, SmartText parses the content of the template into Lua code, so the template should meet Lua syntax requirement, otherwise Lua compiler will complain. <br />
		Another case is that there's no syntax error in template, but the Lua code raises a runtime-error, <br />
		Anyway, SmartText will get the error message and display into the text box.<br />
		Look at the following example:
    
    </p>
    <div class="sc99">
        <span class="sc17">#{for i = 1, 5}<br />
        </span><span class="sc0">i = </span><span class="sc16">${i}</span><br />
        <span class="sc17">#{end}</span></div>
    <br />
    <p>
        		The template does not require a parameter file to run, but an error occurs:
    </p>
    <img src="Images/error_english.jpg" />
    <p>
        		The first line of the text box is the Lua compiler error messages, a compilation error is in the format [string "chunk"]: <i> line </i>: <br />
		Here <i>line</i> is the line number of the wrong Lua code. Following is a detailed description of the error ("do" was missing) <br />
		After second line is the parsed Lua code based on the template, for ease of viewing, SmartText added the line number before each line.<br />
		<br />
		From the parsed Lua code, we can see some details of processing template in SmartText: <br />
		1. The content in flow controlling #{...} is parsed directly into Lua code (like "for" and "end" in the example); <br />
		2. "RenderText" is a SmartText's internal function, which returns the generated text; <br/>
		3. Use [=[ and ]=] to surround normal string, prevent string from being escaped; <br />
		4. "return 0" at last is a fixed statement added by SmartText
    
    </p>
    <h3>
        <a name="undefine variable">Undefined Variable Error</a></h3>
    		When variable used does not exist in parameter, this error occurs, such as the following template: <br />
    
    <br />
    <div class="sc99">
        <span class="sc16">${a}</span><span class="sc0"> + </span><span class="sc16">${b}</span><span
            class="sc0"> + </span><span class="sc16">${c}</span></div>
    <br />
    <p>
        		If you do not use any parameter file, the template will raise the following error:
    
    </p>
    <div class="error">
        [string&nbsp;"chunk"]:1:&nbsp;attempt&nbsp;to&nbsp;concatenate&nbsp;global&nbsp;'c'&nbsp;(a&nbsp;nil&nbsp;value)<br />
        Lua&nbsp;Source:<br />
        &nbsp;&nbsp;1&nbsp;:&nbsp;RenderText(1,&nbsp;[=[]=]&nbsp;..&nbsp;(a)&nbsp;..&nbsp;[=[&nbsp;+&nbsp;]=]&nbsp;..&nbsp;(b)&nbsp;..&nbsp;[=[&nbsp;+&nbsp;]=]&nbsp;..&nbsp;(c)&nbsp;..&nbsp;[=[]=],&nbsp;'\r\n');&nbsp;<br />
        &nbsp;&nbsp;2&nbsp;:&nbsp;return&nbsp;0<br />
    </div>
    <p>
        		Error message clearly indicates which variable does not exist, and the location where variable appears.
	
    </p>
    <p>
        		In addition, if you specify a parameter file, SmartText will also append the parsed Lua code of the parameter file to the end of the text box in order to analyze the error.
    
    </p>
    <br />
    <hr />
    <h2>
        <a name="command line">Command Line</a></h2>
    <p>
        		SmartText can use the command-line parameters in the following format:
    
    </p>
    <div class="sc99" style="font-size: small">
        SmartText.exe <i>template</i> [<i>parameter</i> [<i>output</i> [<i>template encoding</i>
        [<i>parameter encoding</i> [<i>output encoding</i>]]]]]
    </div>
    <p>
        		Respectively, template file, parameter file, output file, encoding of template file, encoding of parameter file, encoding of output file.<br />
		Where the template file must be specified, the others can be omitted.<br />
		The 4th to 6th parameter is required to be the Code Page of the encoding (an integer),  you can get it in the setting window of SmartText.<br />
		Here is an example of using the command-line parameters:
    
    </p>
    <div class="sc99" style="font-size: small">
        SmartText.exe "d:\template.txt" "" "d:\output.txt" 936 0 65001
    </div>
    <p>
        		Use "d:\template.txt" as template file, no parameter file, uses "d:\output.txt" as output file, the template file encoding is GB2312, and the output file encoding is UTF-8.
    
    </p>
    <p>
        		When successes, the output file will be generated and a zero value will be returned, in addition to this, no any other prompt.<br />
		If failed, the GUI of SmartText will be displayed, the methods described in <a href="#error handling">Error Handling</a> will help you figure out what went wrong.
    
    </p>
</body>
</html>

